package org.cx.comparator.compare.mode.impl;

import org.cx.comparator.compare.mode.ComparatorMode;
import org.cx.comparator.compare.mode.ComparatorModeContext;

import java.math.BigDecimal;


public class DefaultComparatorMode implements ComparatorMode {

    @Override
    public boolean equatorMode(ComparatorModeContext comparatorModeContext) {
        Object source = comparatorModeContext.getSource();
        Object target = comparatorModeContext.getTarget();
        if (source == null && target == null) {
            return true;
        }
        if (source != null) {
            if (source.equals(target)) {
                return true;
            }
        }
        if (target != null) {
            if (target.equals(source)) {
                return true;
            }
        }
        if (source instanceof BigDecimal && target instanceof BigDecimal) {
            if (((BigDecimal) source).compareTo((BigDecimal) target) == 0) {
                return true;
            }
        }
        return false;
    }
}
